//
//  CommunityTableCellOfText.m
//  aMoment
//
//  Created by dllo on 15/10/7.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "CommunityTableCellOfText.h"
#import "AllHeaderFiles.h"

@implementation CommunityTableCellOfText

- (void)dealloc
{
    [_titleLabel release];
    [_contentLabel release];
    [_addTimeLabel release];
    [_commentNumField release];
    [_community release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    _titleLabel = [[UILabel alloc] init];
//    _titleLabel.backgroundColor = [UIColor grayColor];
    _titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    _contentLabel = [[UILabel alloc] init];
//    _contentLabel.backgroundColor = [UIColor grayColor];
    _contentLabel.numberOfLines = 0;
    _contentLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_contentLabel];
    [_contentLabel release];
    
    _addTimeLabel = [[UILabel alloc] init];
//    _addTimeLabel.backgroundColor = [UIColor grayColor];
    _addTimeLabel.font = [UIFont systemFontOfSize:FONTSIZE_SMALL];
    _addTimeLabel.textColor = FONTCOLOR_GRAY;
    [self.contentView addSubview:_addTimeLabel];
    [_addTimeLabel release];
    
    _commentNumField = [[UITextField alloc] init];
//    _commentNumField.backgroundColor = [UIColor grayColor];
    _commentNumField.enabled = NO;
    _commentNumField.textColor = FONTCOLOR_GRAY;
    _commentNumField.font = [UIFont systemFontOfSize:FONTSIZE_SMALL];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, IMAGE_16, IMAGE_16)];
    imageView.image = [UIImage imageNamed:@"iconfont-message"];
    _commentNumField.leftView = imageView;
    _commentNumField.leftViewMode = UITextFieldViewModeAlways;
    [self.contentView addSubview:_commentNumField];
    [_commentNumField release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _titleLabel.frame = CGRectMake(20 * FIT_WIDTH, 15 * FIT_HEIGHT, self.contentView.Width - 40 * FIT_WIDTH, 20 * FIT_HEIGHT);
    _contentLabel.frame = CGRectMake(_titleLabel.X, _titleLabel.Y + _titleLabel.Height + 15 * FIT_HEIGHT, _titleLabel.Width, self.contentView.Height - 100 * FIT_HEIGHT);
    _addTimeLabel.frame = CGRectMake(_contentLabel.X, _contentLabel.Y + _contentLabel.Height + 15 * FIT_HEIGHT, 85 * FIT_WIDTH, _titleLabel.Height);
    _commentNumField.frame = CGRectMake(_contentLabel.X + _contentLabel.Width - 60 * FIT_WIDTH, _addTimeLabel.Y, 60 * FIT_WIDTH, _titleLabel.Height);
}

- (void)setCommunity:(Community *)community
{
    if (_community != community) {
        [_community release];
        _community = [community retain];
    }
    _titleLabel.text = _community.title;
    _contentLabel.text = _community.content;
    _addTimeLabel.text = _community.addtime_f;
    _commentNumField.text = [NSString stringWithFormat:@" %@", [_community.counterList objectForKey:@"comment"]];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
